Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject to_mem on primitive types in storage #801

Merged
merged 1 commit into from
Oct 26, 2022

Conversation

cburgdorf
Copy link
Collaborator

What was wrong?

The following code is currently not rejected by the compiler even though it should.

contract Test {
   foo: u256

    pub fn bar(self)-> u256{
        return self.foo.to_mem()
    }
}

How was it fixed?

If a value is in storage, check if it is a primitive and if so present the user error

@cburgdorf
Copy link
Collaborator Author

See related discussion on discord https://discord.com/channels/834132302031487017/834132302685536258

@@ -1767,7 +1767,21 @@ fn expr_call_builtin_value_method(
vec![],
);
}
Location::Storage { .. } => {}
Location::Storage { .. } => {
if value_attrs.typ.is_base(context.db()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also have to handle the case where typ == Type::Contract(_) because it's a newtype'd address and is treated as a base type internally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed it.

Copy link
Member

@Y-Nak Y-Nak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cburgdorf cburgdorf merged commit 5b8ef4e into ethereum:master Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants